
//
//  MyCollectionViewCell.m
//  MedicineBox
//
//  Created by dllo on 15/8/24.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "MyCollectionViewCell.h"
#import "UIImageView+WebCache.h"
#import "HomeModel.h"

#import "DKNightVersion.h"
@interface MyCollectionViewCell ()
@property (nonatomic, retain) UIImageView *logoImage;
@property (nonatomic, retain) UILabel *nameLabel;

@end

@implementation MyCollectionViewCell

-(void)dealloc
{
    [_logoImage release];
    [_nameLabel release];
    [super dealloc];
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [DKNightVersionManager addClassToSet:self.class];
        self.nightBackgroundColor = UIColorFromRGB(0x343434);
        
        self.logoImage = [[UIImageView alloc] init];
        [self.contentView addSubview:self.logoImage];
        [_logoImage release];
        
        self.nameLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.nameLabel];
        [_nameLabel release];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.logoImage.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height - 30);
    self.logoImage.backgroundColor = [UIColor clearColor];
    self.logoImage.nightBackgroundColor = UIColorFromRGB(0x343434);
    self.nameLabel.frame = CGRectMake(0, self.logoImage.frame.size.height + self.logoImage.frame.origin.y + 10, _logoImage.frame.size.width, 20);
    _nameLabel.numberOfLines = 0;
    self.nameLabel.font = [UIFont systemFontOfSize:11];
    self.nameLabel.textAlignment = NSTextAlignmentCenter;
    self.nameLabel.nightTextColor = [UIColor whiteColor];
}

- (void)valueWithModel:(HomeModel *)model
{
    [self.logoImage sd_setImageWithURL:[NSURL URLWithString:model.titleimg]];
    CGFloat height = [self countHeight:model.namecn];
    self.nameLabel.frame = CGRectMake(0, self.logoImage.frame.size.height + self.logoImage.frame.origin.y + 10, _logoImage.frame.size.width, height + 5);
    self.nameLabel.text = model.namecn;
    
}

- (CGFloat)countHeight:(NSString *)text
{

  CGSize size =  CGSizeMake(_logoImage.frame.size.width, 100);
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:11],NSFontAttributeName, nil];
   CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height;

}









@end
